﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using lgweb.common;
using LGCourt.Logic.BLL;
using LGCourt.Logic.Common;
using KMFrame.Core;
using LGCourt.Logic.NBL.DBEntities;

namespace lgweb.inside.culture
{
    public partial class imglist : NeedValidatePage
    {
        private int _pageIndex = 1;
        private string _cate = "3";
        private string _cateName = "书画摄影";
        private string _dept = string.Empty;
        private string _keyword = string.Empty;
        private string _start = string.Empty;
        private string _end = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                GetParam();
                GetDepartmentList();
                GetList();
            }
        }

        private void GetParam()
        {
            this._cate = string.IsNullOrEmpty(Request.QueryString["cate"]) ? "1" : Request.QueryString["cate"];
            this._dept = string.IsNullOrEmpty(Request.QueryString["dept"]) ? "" : Request.QueryString["dept"];
            this._keyword = string.IsNullOrEmpty(Request.QueryString["keyword"]) ? "" : Request.QueryString["keyword"];
            this._start = string.IsNullOrEmpty(Request.QueryString["start"]) ? "" : Request.QueryString["start"];
            this._end = string.IsNullOrEmpty(Request.QueryString["end"]) ? "" : Request.QueryString["end"];
            this.hdnCate.Value = this._cate;
            switch (_cate)
            {
                case "1":
                    this._cateName = "文苑沙龙";
                    break;
                case "2":
                    this._cateName = "他山之石";
                    break;
                case "3":
                    this._cateName = "书画摄影";
                    break;
                case "4":
                    this._cateName = "文体生活";
                    break;
                default:
                    this._cateName = "文苑沙龙";
                    break;

            }
            this._pageIndex = string.IsNullOrEmpty(Request.QueryString["PageIndex"]) ? 1 : Convert.ToInt32(Request.QueryString["PageIndex"]);
        }

        //绑定部门
        private void GetDepartmentList()
        {
            DepartmentHandler bll = new DepartmentHandler();
            List<Department> result = (List<Department>)bll.GetDepartmentList();
            if (result != null && result.Count > 0)
            {
                Department PleaseLocation = new Department();
                PleaseLocation.Code = "0";
                PleaseLocation.Name = "选择部门";
                result.Insert(0, PleaseLocation);
                this.sltDepartment.DataSource = result;
                this.sltDepartment.DataTextField = "Name";
                this.sltDepartment.DataValueField = "Name";
                this.sltDepartment.DataBind();
                this.sltDepartment.Value = this._dept;
            }
        }

        private void GetList()
        {
            BBS bll = new BBS();
            InfoCondition param = new InfoCondition();
            param.PageSize = 20;
            param.PageIndex = this._pageIndex;
            param.InfoTag = this._cateName;
            if (!string.IsNullOrEmpty(this._start))
            {
                param.BegingDate = Utils.ConvertUnixTimeStampToDateTime(this._start);
            }
            if (!string.IsNullOrEmpty(this._end))
            {
                param.EndDate = Utils.ConvertUnixTimeStampToDateTime(this._end);
            }
            param.keyword = this._keyword;
            param.from = this._dept;

            PageResult result = (PageResult)bll.GetNewsInfoPage(param);

            if (result != null && result.ResultList != null)
            {
                this.rptPicnews.DataSource = (List<vPortalArticleTitleEx>)result.ResultList;
                this.rptPicnews.DataBind();
                this.pager1.RecordCount = result.TotalCount;
                this.pager1.TotalPage = result.PageCount;
                this.pager1.PageIndex = this._pageIndex;
                this.pager1.PageSize = 20;
                this.pager1.LinkUrl = string.Format("/inside/culture/imglist.aspx?PageIndex={0}&cate={1}&keyword={2}&dept={3}&start={4}&end={5}", this._pageIndex, _cate,this._keyword,this._dept,this._start,this._end);
            }
        }

    }
}